package com.shiliuzi.www.util.powerUtil;

import com.shiliuzi.www.common.Code;
import com.shiliuzi.www.exception.GlobalException;
import com.shiliuzi.www.pojo.bo.PowerBo;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class PowerUtil {

    @Pointcut(value = "@annotation(com.shiliuzi.www.util.powerUtil.Power)")
    public void checkPower() {

    }

    @Before("@annotation(power)")
    public void checkOptional(Power power) {
        log.info("该方法需要有{}号权利！现在进行检查！",power.powId());
        if(!PowerBo.collatePower(Integer.valueOf(power.powId())))
            throw new GlobalException(Code.ERROR,"您没有相关权利！");
    }
}
